package com.cyf.db.mapper;

import com.cyf.db.bean.PiaoTong;
import com.cyf.db.bean.PiaotongPark;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PiaoTongMapper {


    @Select(" SELECT * FROM piaotong_invoice WHERE parkingId = #{parkingId} AND  FIND_IN_SET(#{localInoutparkingId},localInoutparkingId)")
    PiaoTong selectPiaoTongByInoutParkingId(@Param("parkingId") Integer parkingId, @Param("localInoutparkingId") Integer localInoutparkingId);

    @Select("select taxpayerNum, taxRate from piaotong_park where parkingId = #{parkingId} limit 0,1")
    PiaotongPark getTaxpayerNumAndTaxRateByParkingId(@Param("parkingId") Integer parkingId);

    @Select("<script>" +
            " SELECT ice.*,ice.createdTime AS createTime FROM piaotong_invoice AS ice  \n" +
            " LEFT JOIN local_inoutparking AS ip on FIND_IN_SET(ip.localInoutparkingId,ice.localInoutparkingId) AND ice.parkingId = ip.parkingId " +
            " WHERE ip.carLicense IN " +
            " <foreach item=\"item\" index=\"index\" collection=\"plates\" open=\"(\" separator=\",\" close=\")\">  \n" +
            "  #{item}   " +
            " </foreach>  " +
            " GROUP BY ice.id ORDER BY ice.createdTime DESC" +
            "</script>")
    List<PiaoTong> selectPiaoTongListByPlate(@Param("plates") List<String> plates);

    @Delete(" DELETE FROM piaotong_invoice WHERE id = #{id} ")
    void deletePiaotongInvoiceById(@Param("id") Integer id);
}
